﻿using Phones.Client.Repository;
using Phones.Client.Model;

namespace Phones.Client.ViewModel
{
    public class OrganisationTreeNodeViewModel: TreeViewItemBaseViewModel
    {
        private Organisation _organisation;

        public Organisation Model
        { get { return _organisation; } }

        public OrganisationTreeNodeViewModel(ServiceNodeTreeNodeViewModel parent, Organisation organisation)
            : base(parent, true)
        {
            _organisation = organisation;
        }

        protected override void LoadChildren()
        {
            Children.Clear();

            using (var db = new DepartmentsRepository())
            {
                var list = db.GetList(
                        (Parent as ServiceNodeTreeNodeViewModel).Model,
                        _organisation
                    );

                foreach (var item in list)
                {
                    Children.Add(new DepartnemtTreeNodeViewModel(this, item));
                }
            }
        }
    }
}
